//
//  LoginViewController.m
//  App-MyFairldy
//
//  Created by 客官大大 on 15/5/23.
//  Copyright (c) 2015年 客官大大. All rights reserved.
//

#import "LoginViewController.h"
#import "UMSocial.h"
#import "UMSocialSinaHandler.h"
#import "UMSocialSinaSSOHandler.h"


@interface LoginViewController ()

@end

@implementation LoginViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    UIImageView *view = [[UIImageView alloc] initWithFrame:CGRectMake(0, 64, self.view.frame.size.width, self.view.frame.size.height - 500)];
//    view.backgroundColor = [UIColor yellowColor];
    view.image = [UIImage imageNamed:@"apic9649.jpg"];
    view.alpha = 0.2;
    [self.view addSubview:view];
    
//    UIImageView *view1 = [[UIImageView alloc] initWithFrame:CGRectMake(140, 40, 100, 100)];
//    view1.backgroundColor = [UIColor whiteColor];
//    UIImage *image = [UIImage imageNamed:@"iconfont-denglu"];
//    view1.image = image;
//    
//    [view1 setUserInteractionEnabled:YES];
//    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(touchi:)];
//    tap.delegate = self;
////    [view1 addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(clickCategory:)]];
//    [view1 addGestureRecognizer:tap];
//
//    [view addSubview:view1];
    
    button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.frame = CGRectMake(140, 100, 100, 100);
    [button setImage:[UIImage imageNamed:@"iconfont-denglu"] forState:UIControlStateNormal];
    [button addTarget:self action:@selector(touchi) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:button];
    
    
    
    UITableView *table = [[UITableView alloc] initWithFrame:CGRectMake(0, 250, 375, 100) style:UITableViewStylePlain];

    table.delegate = self;
    table.dataSource = self;
    [self.view addSubview:table];
    
}
-(void)touchi
{
    [UMSocialSinaHandler openSSOWithRedirectURL:@"http://www.yshow.net"];
    NSString *platftname = [UMSocialSnsPlatformManager getSnsPlatformString:UMSocialSnsTypeSina];
    UMSocialSnsPlatform *snsplatform = [UMSocialSnsPlatformManager getSocialPlatformWithName:UMShareToSina];
    snsplatform.loginClickHandler(self,[UMSocialControllerService defaultControllerService],YES,^(UMSocialResponseEntity *response){
        NSLog(@"response is %@",response);
        if (response.responseCode == UMSResponseCodeSuccess) {
            UMSocialAccountEntity *snsaccount = [[UMSocialAccountManager socialAccountDictionary] valueForKey:platftname];
            NSLog(@"=====%@",snsaccount.userName
                  );
            
//            NSDictionary *dic = [[response.data allKeys] objectAtIndex:0];
//            NSString *str = [dic objectForKey:@"sina"];
//            NSLog(@"%@",str);
     
            
            
            
            
            NSURL *url = [NSURL URLWithString:snsaccount.iconURL];
            NSData *data = [NSData dataWithContentsOfURL:url];
            UIImage *image3 = [UIImage imageWithData:data];
    
    [button setImage:image3 forState:UIControlStateNormal];
        }
        
    });
    

    
}
-(void)didFinishGetUMSocialDataInViewController:(UMSocialResponseEntity *)response

{
   
    if (response.viewControllerType == UMSViewControllerOauth) {
      
        NSLog(@"didFinishOauthAndGetAccount response is %@",response);
        
    }
 
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *indent = @"cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:indent];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:indent];
        if (indexPath.row == 0) {
            cell.textLabel.text = @"我的收藏";
        }else if (indexPath.row == 1){
        cell.textLabel.text = @"清除缓存";
        }
    }
    return cell;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 2;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
